import { Column, Entity, Index } from 'typeorm';
import { CommonEntity, CommonStatus } from '~/common/entity/common.entity';
import { ModuleTypeEnums } from '~/constants/modules.constant';

@Entity('ah_message')
@Index(['recipientId', 'id'])
export class MessageEntity extends CommonEntity {
  @Column({ type: 'int', comment: '消息发送者', name: 'recipient_id' })
  recipientId: number;

  @Column({ type: 'varchar', length: 255, comment: '消息标题', nullable: true, default: null })
  title: string;

  @Column({ type: 'text', comment: '消息内容', nullable: true, default: null })
  content: string;

  @Column({ type: 'tinyint', width: 1, comment:'消息类型', default: ModuleTypeEnums.SYSTEM })
  type: ModuleTypeEnums;

  @Column({
    type: 'tinyint', width: 1,
    comment: '已读',
    name: 'is_read',
    default: CommonStatus.NO,
  })
  isRead: CommonStatus;

  @Column({ type: 'date', comment: '消息读取时间', name: 'read_at', default: null })
  readAt: Date;
}
